function reloadTab(){
	jQuery.modal.close();
	jQuery('#escort-option').tabs( "load" , 0 );
}
function openPopup(){
	jQuery('#basic-modal-content-language').modal({
		onClose:reloadTab
	});
	jQuery("select#language_code").trigger("liszt:updated");
}

function saveLanguage(){
	if(validate()){
		if(jQuery('#language_id').val() == ""){
			jQuery.post("./admin/database_definition/languages/ajax_language_save", { language: jQuery("#language").val(), language_code: jQuery("#language_code").val()},
				function(data) {
					res = eval('(' + data + ')');
					if(res.result){
						jQuery('#escort-option').tabs( "load" , 0 );
						jQuery.modal.close();
						if(jQuery('#content-body div.alert').length){
							jQuery('#content-body div.alert').remove();
						}
						jQuery('#content-body').prepend('<div class="alert success">'+ res.message+'</div>');
					}else{
						if(jQuery('form#add-language-form section.item div.alert').length){
							jQuery('form#add-language-form section.item div.alert').remove();
						}
						jQuery('form#add-language-form section.item').prepend('<div class="alert error">'+ res.message+'</div>');
					}
				}
			);
		}else{
			jQuery.post("./admin/database_definition/languages/ajax_language_update", {id: jQuery('#language_id').val(), language: jQuery("#language").val(), language_code: jQuery("#language_code").val()},
				function(data) {
					res = eval('(' + data + ')');
					if(res.result){
						jQuery('#language_id').val("");
						jQuery("#language").val("");
						jQuery('#escort-option').tabs( "load" , 0 );
						jQuery.modal.close();
						if(jQuery('#content-body div.alert').length){
							jQuery('#content-body div.alert').remove();
						}
						jQuery('#content-body').prepend('<div class="alert success">'+ res.message+'</div>');
					}else{
						if(jQuery('form#add-language-form section.item div.alert').length){
							jQuery('form#add-language-form section.item div.alert').remove();
						}
						jQuery('form#add-language-form section.item').prepend('<div class="alert error">'+ res.message+'</div>');
					}
			 	}
			);
		}
	}else{
		return false;
	}
}
function validate(){
	return true;
}
function editLanguage(id){
	jQuery.post("./admin/database_definition/languages/ajax_language_get", { id: id},
		function(data) {
			res = eval('(' + data + ')');
			jQuery('#basic-modal-content-language').modal({
				onClose:reloadTab
			});
			jQuery('#language').val(res.language);
			jQuery('#language_code').val(res.code);
			jQuery('#language_id').val(res.id);
			jQuery("select#language_code").trigger("liszt:updated");
	 	}
	);
	return false;
}
function deleteLanguage(id, message){
	confirm(message, function () {
		jQuery.post("./admin/database_definition/languages/ajax_language_delete", { id: id},
			function(data) {
				jQuery('#escort-option').tabs( "load" , 0 );
				if(jQuery('#content-body div.alert').length){
					jQuery('#content-body div.alert').remove();
				}
				jQuery('#content-body').prepend('<div class="alert success">'+ data.message+'</div>');
		 	}, "json"
		);
		return false;
	});
	return false;
}